/*
 * @Author: your name
 * @Date: 2021-08-31 14:13:13
 * @LastEditTime: 2021-09-01 10:05:20
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \jinfeng_up\src\utils\checkPermi.js
 */
/**
 * 字符权限校验
 * @param {Array} value 校验值
 * @returns {Boolean}
 */
export function checkPermi(value) {
    if (value && value instanceof Array && value.length > 0) {
        const permissions = JSON.parse(sessionStorage.getItem('BUTTONLIST') || '[]')
        const arrs = []
        permissions.forEach(element => {
            arrs.push(element.permCode)
        })

        const permissionDatas = value
        const all_permission = ''

        const hasPermission = arrs.some(permission => {
            console.log('permission', permission)
            return all_permission === permission || permissionDatas.includes(permission)
        })

        if (!hasPermission) {
            return false
        }
        return true
    } else {
        console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
        return false
    }
}
